package com.open.launcher.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据整体类型分为:栏目,影片,影片基本信息.Content是返回各类型数据的基类.
 *
 * @author Richard
 */
public class Content implements Parcelable {
    /**
     * VOD电影
     */
    public static final String VOD_TYPE = "vod";
    /**
     * 电视剧
     */
    public static final String TELE_TV_TYPE = "sitcom";
    /**
     * 回看
     */
    public static final String TVOD_TYPE = "tvod_type";
    /**
     *直播
     */
    public static final String LIVE_TYPE="tv";
    /**
     * 视频列表(首页item链接到视频列表直接播放)
     */
    public static final String VOD_LIST = "vodlist";
    /**
     * 综艺列表（首页item链接到综艺页面）
     */
    public static final String VARIETY_LIST = "varietylist";
    /**
     * 专题（首页item链接到专题）
     */
    public static final String SPECIAL_TYPE = "speical_modle";
    /**
     * 直接播放（首页item直接播放）
     */
    public static final String VIDEO_TYPE = "video_type";
    /**
     * 图片（首页item链接到图片）
     */
    public static final String IMAGE_TYPE = "image_type";
    /**
     * 链接到图片列表
     */
    public static final String IMAGE_LIST = "image_list";
    /**
     * 打开app（首页item直接打开存在的app,配置文件里的contentId为app包名，itemName为app名称）
     */
    public static final String START_APP = "start_other_app";
    /**
     * 综艺
     */
    public static final String VARIETY_TYPE = "variety";
    /**
     * 首页链接到电影或者电视剧并进入详情页
     */
    public static final String VOD_TELL_DETAIL_LIST = "vod_tell_detail";
    /**
     * 广告图片
     */
    public static final String AD_IMAGE_TYPE = "17";
    /**
     * 广告影视
     */
    public static final String AD_VIDEO_TYPE = "18";
    /**
     * 普通少儿
     */
    public static final String CHILDREN_1_TYPE = "19";
    /**
     * 专题少儿
     */
    public static final String CHILDREN_2_TYPE = "20";
    /**
     * 父栏目id
     */
    public String parentID;
    /**
     * id
     */
    public String contentID;
    /**
     * name
     */
    public String name;
    /**
     * 图片源
     */
    public ImageSource imgSource;
    /**
     * 内容类型
     */
    public String type;
    /**
     * 是否为历史记录对象,0:不是历史对象,1:是历史对象
     */
    public int isHistory = 0;
    /**
     * 是否为收藏,0:不是收藏,1:是收藏
     */
    public int isFavourite = 0;
    /**
     * 最后播放的日期
     */
    public long lastVisitDate;
    /**
     * 入库时间
     */
    public long insertTime;
    /**
     * 附加信息
     */
    public Map extras;

    public Content() {
        this("", "", "", new ImageSource(), "");
    }

    public Content(String parentID, String contentID, String name, ImageSource imgSource, String type) {
        this.parentID = (parentID == null ? "" : parentID);
        this.contentID = (contentID == null ? "" : contentID);
        this.name = (name == null ? "" : name);
        this.imgSource = imgSource;
        this.type = type;
        this.extras = new HashMap();
    }

    // ---------------------Parcelable implements------------

    @Override
    public String toString() {
        return "Content [parentID=" + parentID + ", contentID=" + contentID + ", name=" + name + ", imgSource=" + imgSource + "]";
    }

    public static final Creator<Content> CREATOR = new Creator<Content>() {

        @Override
        public Content createFromParcel(Parcel source) {
            String parentID = source.readString();
            String contentID = source.readString();
            String name = source.readString();
            ImageSource imgSource = source.readParcelable(ImageSource.class.getClassLoader());
            String type = source.readString();
            int isHistory = source.readInt();
            Map extras = source.readHashMap(HashMap.class.getClassLoader());
            Content content = new Content(parentID, contentID, name, imgSource, type);
            content.isHistory = isHistory;
            content.extras = extras;
            return content;
        }

        @Override
        public Content[] newArray(int size) {
            return new Content[size];
        }

    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(parentID);
        dest.writeString(contentID);
        dest.writeString(name);
        dest.writeParcelable(imgSource, flags);
        dest.writeString(type);
        dest.writeInt(isHistory);
        dest.writeMap(extras);
    }
}
